import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
// 一级路由
// 工作台
import park from './modules/park'
// 行车管理
import car from './modules/car'
// 物业费管理
import managementFee from './modules/managementFee'
// 一体杆管理
import pole from './modules/pole'
// 系统管理
import system from './modules/system'

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [{
  path: '/login',
  component: () =>
    import ('@/views/login/index')
  // hidden: true
},

{
  path: '/404',
  component: () =>
    import ('@/views/404'),
  hidden: true
},

{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: 'Dashboard',
    component: () =>
      import ('@/views/dashboard/index'),
    meta: { title: '工作台', icon: 'dashboard' }
  }]
},
park,
car,
managementFee,
pole,
system,
// 新增月卡管理页
{
  path: '/cardAdd',
  component: () =>
    import ('@/views/car/CarCard/add-card.vue')
},
// 添加企业
{
  path: '/enterpriseAdd',
  component: () =>
    import ('@/views/park/enterprise/add.vue')
},
// 查看企业
{
  path: '/exterpriseDetail',
  component: () =>
    import ('@/views/park/enterprise/detail')
},
// 系统管理-角色管理-新增角色
{
  path: '/roleAdd',
  component: () =>
    import ('@/views/system/Role/add.vue')
},
// 404 page must be placed at the end !!!
{ path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
